//
//  UIButtonController.swift
//  HHSwift
//
//  Created by qk-huahong on 2019/8/15.
//  Copyright © 2019 huahong. All rights reserved.
//

import UIKit
import RxSwift
class UIButtonController: BaseViewController {
    
    let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()
        
       title = "UIButton"
        
        var button:UIButton!
        
        if #available(iOS 13.0, *) {
           button = UIButton(type: .close)
        } else {
           button = UIButton(type: .custom)
        }
        
        self.view.addSubview(button)
//        button.frame = CGRect(x: 100, y: 100, width: kScreenWidth, height: 200)
        button.backgroundColor = .red
        button.addTarget(self, action: #selector(buttonAction(sender:)), for: .touchUpInside)
        button.setImage(UIImage(named: "PlayButton"), for: .normal)
        button.setTitle("测试", for: .normal)
        button.contentVerticalAlignment = .center

        button.snp.makeConstraints { (maker) in
//            maker.left.equalToSuperview().offset(100)
//            maker.top.equalToSuperview().offset(100)
            maker.width.equalTo(200)
            maker.height.equalTo(200)
            maker.center.equalToSuperview()
        }
        
        button.rx.tap
            .subscribe(onNext: { (button) in
                print("rx button clicked")
            })
            .disposed(by: disposeBag)
        
        button.layoutEdgeInsetsWithStyle(style: .right, space: 10)
        
    }

    @objc func buttonAction(sender:UIButton)  {
        
        print("button clicked")
    }
}
